<template>
	<div class="dashboard-editor-container">
		<!-- 右上角github图标 -->
		<el-tooltip content="Github源码" effect="dark" placement="bottom">
			<github-corner style="position: absolute; top: 0px; border: 0; right: 0;"></github-corner>
		</el-tooltip>

		<!-- 顶部内容 -->
		<el-row class="panel-group" :gutter="40">
			<el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
				<div class="card-panel">
				<div class="card-panel-icon-wrapper icon-money">
					<svg-icon icon-class="eye" class-name="card-panel-icon"/>
				</div>
				<div class="card-panel-description">
					<div class="card-panel-text">今日IP数：</div>
					<count-to class="card-panel-num" :startVal="0" :endVal="visitAddTotal" :duration="3200"></count-to>
				</div>
				</div>
			</el-col>

			<el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
				<div class="card-panel">
				<div class="card-panel-icon-wrapper icon-people" @click="btnClick('2')">
					<svg-icon icon-class="peoples" class-name="card-panel-icon"/>
				</div>
				<div class="card-panel-description">
					<div class="card-panel-text">用户数:</div>
					<count-to class="card-panel-num" :startVal="0" :endVal="userTotal" :duration="2600"></count-to>
				</div>
				</div>
			</el-col>

			<el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
				<div class="card-panel">
				<div class="card-panel-icon-wrapper icon-message" @click="btnClick('3')">
					<svg-icon icon-class="message" class-name="card-panel-icon"/>
				</div>
				<div class="card-panel-description">
					<div class="card-panel-text">评论数：</div>
					<count-to class="card-panel-num" :startVal="0" :endVal="commentTotal" :duration="3000"></count-to>
				</div>
				</div>
			</el-col>
			<el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
				<div class="card-panel">
				<div class="card-panel-icon-wrapper icon-shoppingCard" @click="btnClick('4')">
					<svg-icon icon-class="form" class-name="card-panel-icon"/>
				</div>
				<div class="card-panel-description">
					<div class="card-panel-text">文章数:</div>
					<count-to class="card-panel-num" :startVal="0" :endVal="blogTotal" :duration="3600"></count-to>
				</div>
				</div>
			</el-col>			
		</el-row>
			
		<el-row>
			<calendar-chart></calendar-chart>
		</el-row>

		<el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
			<line-chart :chart-data="lineChartData"></line-chart>
		</el-row>
	</div>
</template>

<script>
import GithubCorner from "@/components/GithubCorner";
import CountTo from "vue-count-to";
import { init, getVisitByWeek } from "@/api/dashboard";
import CalendarChart from "@/components/CalendarChart";
import LineChart from "@/components/LineChart";

export default {
	name: "dashboard",
	components: {
		GithubCorner,
		CountTo,
		CalendarChart,
		LineChart
	},
	created(){
		init().then(response => {
			if (response.data.code == "success") {
				let data = response.data.data;
				this.blogTotal = data.blogCount;
				this.commentTotal = data.commentCount;
				this.userTotal = data.userCount;
				this.visitAddTotal = data.visitCount;
			}
		});

		getVisitByWeek().then(response => {
			console.log(response.data.code === "success")
			if (response.data.code === "success") {
				let visitByWeek = response.data.data;
				let lineChartData = {
					date: visitByWeek.date,
					pvData: visitByWeek.pv,
					uvData: visitByWeek.uv
				};
				this.lineChartData = lineChartData;
				console.log(this.lineChartData)
			}
		});
	},
	data(){
		return {
			visitAddTotal: 0,
			userTotal: 0,
			commentTotal: 0,
			blogTotal: 0,
			lineChartData: {}		
		}
	}
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}
.btn {
  width: 80px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  font-size: 14px;
  display: inline-block;
  white-space: nowrap;
  cursor: pointer;
  background: #fff;
  border: 1px solid #dcdfe6;
  color: #606266;
}

.btnClick {
  color: #409eff;
  border-color: #c6e2ff;
  background-color: #ecf5ff;
}

.btn:hover {
  color: #409eff;
  border-color: #c6e2ff;
  background-color: #ecf5ff;
}

.statistics-item {
  width: 600px;
  height: 400px;
  float: left;
  margin: 20px auto;
}

.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.05);
    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }
      .icon-people {
        background: #40c9c6;
      }
      .icon-message {
        background: #36a3f7;
      }
      .icon-money {
        background: #f4516c;
      }
      .icon-shoppingCard {
        background: #34bfa3;
      }
    }
    .icon-people {
      color: #40c9c6;
    }
    .icon-message {
      color: #36a3f7;
    }
    .icon-money {
      color: #f4516c;
    }
    .icon-shoppingCard {
      color: #34bfa3;
    }
    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }
    .card-panel-icon {
      float: left;
      font-size: 48px;
    }
    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px 70px 0 0;
      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }
      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}
</style>